package com.szt.sy.service.system.rolefhbutton;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.szt.sy.entity.system.RoleFhbutton;
import com.szt.sy.mapper.system.RoleFhbuttonMapper;

/***
 * 角色按钮权限服务
 * 
 * @author wwy
 *
 */
@CacheConfig(cacheNames = "roleFhbuttonCache")
@Service("roleFhbuttonService")
@Transactional(rollbackFor = RuntimeException.class)
public class RoleFhbuttonService {
	
	@Autowired
	private RoleFhbuttonMapper roleFhbuttonMapper;
	
	/**
	 * 新增
	 *
	 * @param roleFhbutton
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void save(RoleFhbutton entity) throws Exception {
		
		roleFhbuttonMapper.insert(entity);
	}
	
	/**
	 * 通过(角色ID和按钮ID)获取数据
	 *
	 * @param roleId
	 * @param buttonId
	 * @throws Exception
	 */
	@Cacheable
	public RoleFhbutton findByRoleId(String roleId, String buttonId) throws Exception {
		RoleFhbutton entity = new RoleFhbutton();
		entity.setButtonId(buttonId);
		entity.setRoleId(roleId);
		return roleFhbuttonMapper.selectOne(entity);
	}
	
	/**
	 * 删除
	 *
	 * @param id
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void delete(String id) throws Exception {
		roleFhbuttonMapper.deleteById(id);
	}
	
	/**
	 * 列表(全部)
	 *
	 * @param map
	 * @throws Exception
	 */
	@Cacheable
	public List<RoleFhbutton> listAll(Map<String, Object> map) throws Exception {
		return roleFhbuttonMapper.listAll(map);
	}
	
	/**
	 * 列表(全部)左连接按钮表,查出安全权限标识
	 *
	 * @param map
	 * @throws Exception
	 */
	@Cacheable
	public List<RoleFhbutton> listAllBrAndQxname(Map<String, Object> map) throws Exception {
		return roleFhbuttonMapper.listAllBrAndQxname(map);
	}
	
}
